Micron Document
`:top
The `!Pan–Tompkins algorithm`!`:cite-ref-pantompkins-1-0[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f] is commonly used to detect `F33f`_`[QRS complexes`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QRS_complexes]`_`f in electrocardiographic signals (`F33f`_`[ECG`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ECG]`_`f). The QRS complex represents the ventricular `F33f`_`[depolarization`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Depolarization]`_`f and the main spike visible in an ECG `F33f`_`[signal`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Signal]`_`f (see figure). This feature makes it particularly suitable for measuring `F33f`_`[heart rate`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Heart_rate]`_`f, the first way to assess the heart health state. In the first derivation of `F33f`_`[Einthoven`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Einthoven]`_`f of a physiological heart, the QRS complex is composed by a downward deflection (Q wave), a high upward deflection (R wave) and a final downward deflection (S wave).

The Pan–Tompkins algorithm applies a series of filters to highlight the frequency content of this rapid heart depolarization and removes the background `F33f`_`[noise`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Noise_reduction]`_`f. Then, it squares the signal to amplify the QRS contribution, which makes identifying the QRS complex more straightforward. Finally, it applies adaptive thresholds to detect the peaks of the filtered signal. The algorithm was proposed by Jiapu Pan and Willis J. Tompkins in 1985, in the journal IEEE Transactions on Biomedical Engineering.`:cite-ref-pantompkins-1-1[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f] The performance of the method was tested on an annotated arrhythmia database (MIT/BIH`:cite-ref-2[`F5bf`_`[2`#cite-note-2]`_`f]`:cite-ref-physionet-3-0[`F5bf`_`[3`#cite-note-physionet-3]`_`f]) and evaluated also in presence of noise. Pan and Tompkins reported that the 99.3 percent of QRS complexes was correctly detected.`:cite-ref-pantompkins-1-2[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f]

>>Contents

• `F0af`_`[Pre-processing`#pre-processing]`_`f
• `F0af`_`[Noise cancellation`#noise-cancellation]`_`f
• `F0af`_`[Derivative step`#derivative-step]`_`f
• `F0af`_`[Squaring and integration`#squaring-and-integration]`_`f
• `F0af`_`[Decision rules`#decision-rules]`_`f
• `F0af`_`[Fiducial mark`#fiducial-mark]`_`f
• `F0af`_`[Thresholds`#thresholds]`_`f
• `F0af`_`[Search back for missed QRS complexes`#search-back-for-missed-qrs-complexes]`_`f
• `F0af`_`[T wave discrimination`#t-wave-discrimination]`_`f
• `F0af`_`[Application`#application]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f

-─

>>Pre-processing

>>>Noise cancellation

As a first step, a `F33f`_`[band-pass filter`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Band-pass_filter]`_`f is applied to increase the `F33f`_`[signal-to-noise ratio`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Signal-to-noise_ratio]`_`f. A filter bandwidth of 5-15 `F33f`_`[Hz`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Hertz]`_`f is suggested to maximize the QRS contribute and reduce muscle noise, baseline wander, powerline interference and the `F33f`_`[P wave`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=P_wave_(electrocardiography)]`_`f/`F33f`_`[T wave`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=T_wave]`_`f frequency content.`:cite-ref-pantompkins-1-3[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f] In the original algorithm proposed in 1985, the band-pass filter was obtained with a `F33f`_`[low-pass filter`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Low-pass_filter]`_`f and a `F33f`_`[high-pass filter`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=High-pass_filter]`_`f in cascade to reduce the computational cost and allow a real-time detection, while ensuring a 3 `F33f`_`[dB`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Decibel]`_`f passband in the 5–12 Hz frequency range, reasonably close to the design goal.

For a signal sampled at a frequency of 200 Hz, Pan and Tompkins suggested the filters with the following `F33f`_`[transfer functions`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Transfer_function]`_`f H ( z ) {\\displaystyle H(z)} in an updated version of their article:`:cite-ref-pterrata-4-0[`F5bf`_`[4`#cite-note-pterrata-4]`_`f]

• H ( z ) = ( 1 − − z − − 5 ) 2 ( 1 − − z − − 1 ) 2 {\\displaystyle H(z)={(1-z^{-5})^{2} \\over (1-z^{-1})^{2}}} for a second-order low-pass filter with a gain of 36 and a processing delay of 5 `F33f`_`[samples`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sampling_(signal_processing)]`_`f;
• H ( z ) = ( − − 1 / 32 + z − − 16 − − z − − 17 + z − − 32 / 32 ) ( 1 − − z − − 1 ) {\\displaystyle H(z)={(-1/32+z^{-16}-z^{-17}+z^{-32}/32) \\over (1-z^{-1})}} for a high-pass filter with a unity gain and a processing delay of 16 samples.

>>>Derivative step

As a third step, a derivative filter is applied to provide information about the slope of the QRS. For a signal sampled at 200 Hz, Pan and Tompkins suggested the following `F33f`_`[transfer function`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Transfer_function]`_`f:`:cite-ref-pterrata-4-1[`F5bf`_`[4`#cite-note-pterrata-4]`_`f]

H ( z ) = 0.1 ( − − z − − 2 − − 2 z − − 1 + 2 z 1 + z 2 ) {\\displaystyle H(z)=0.1(-z^{-2}-2z^{-1}+2z^{1}+z^{2})} for a 5-point derivative filter with gain of 0.1 and a processing delay of 2 samples.

>>>Squaring and integration

The filtered signal is squared to enhance the dominant peaks (QRSs) and reduce the possibility of erroneously recognizing a T wave as an R peak. Then, a moving average filter is applied to provide information about the duration of the QRS complex. The number of samples to average is chosen in order to average on windows of 150 ms.`:cite-ref-pantompkins-1-4[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f] The signal so obtained is called integrated signal.

>>Decision rules

>>>Fiducial mark

In order to detect a QRS complex, the local peaks of the integrated signal are found. A peak is defined as the point in which the signal changes direction (from an increasing direction to a decreasing direction). After each peak, no peak can be detected in the next 200 ms (i.e. the lockout time). This is a physiological constraint due to the `F33f`_`[refractory period`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Refractory_period_(physiology)]`_`f during which ventricular depolarization cannot occur even in the presence of a stimulus.`:cite-ref-pantompkins-1-5[`F5bf`_`[1`#cite-note-pantompkins-1]`_`f]

>>>Thresholds

Each fiducial mark is considered as a potential QRS. To reduce the possibility of wrongly selecting a noise peak as a QRS, each peak amplitude is compared to a threshold (`*ThresholdI`*) that takes into account the available information about already detected QRS and the noise level:

T h r e s h o l d I = N o i s e L e v e l I + 0.25 ( S i g n a l L e v e l I − − N o i s e L e v e l I ) {\\displaystyle Threshold_{I}=NoiseLevel_{I}+0.25(SignalLevel_{I}-NoiseLevel_{I})}

where `*NoiseLevelI`* is the running estimate of the noise level in the integrated signal and `*SignalLevelI`* is the running estimate of the signal level in the integrated signal.

The threshold is automatically updated after detecting a new peak, based on its classification as signal or noise peak:

S i g n a l L e v e l I = 0.125 P E A K I + 0.875 S i g n a l L e v e l I {\\displaystyle SignalLevel_{I}=0.125PEAK_{I}+0.875SignalLevel_{I}} (if `*PEAKI`* is a signal peak)

N o i s e L e v e l I = 0.125 P E A K I + 0.875 N o i s e L e v e l I {\\displaystyle NoiseLevel_{I}=0.125PEAK_{I}+0.875NoiseLevel_{I}} (if `*PEAKI`* is a noise peak)

where `*PEAKI`* is the new peak found in the integrated signal.

At the beginning of the QRS detection, a 2 seconds learning phase is needed to initialize `*SignalLevelI`* and `*NoiseLevelI`* as a percentage of the maximum and average amplitude of the integrated signal, respectively.

If a new `*PEAKI`* is under the `*ThresholdI`*, the noise level is updated. If `*PEAKI`* is above the `*ThresholdI`*, the algorithm implements a further check before confirming the peak as a true QRS, taking into consideration the information provided by the bandpass filtered signal.

In the filtered signal the peak corresponding to the one evaluated on the integrated signal is searched and compared with a threshold, calculated in a similar way to the previous step:

T h r e s h o l d F = N o i s e L e v e l F + 0.25 ( S i g n a l L e v e l F − − N o i s e L e v e l F ) {\\displaystyle Threshold_{F}=NoiseLevel_{F}+0.25(SignalLevel_{F}-NoiseLevel_{F})}

S i g n a l L e v e l F = 0.125 P E A K F + 0.875 S i g n a l L e v e l F {\\displaystyle SignalLevel_{F}=0.125PEAK_{F}+0.875SignalLevel_{F}} (if `*PEAKF`* is a signal peak)

N o i s e L e v e l F = 0.125 P E A K F + 0.875 N o i s e L e v e l F {\\displaystyle NoiseLevel_{F}=0.125PEAK_{F}+0.875NoiseLevel_{F}} (if `*PEAKF`* is a noise peak)

where the final F stands for filtered signal.

>>>Search back for missed QRS complexes

The algorithm takes into account the possibility of setting too high values of `*ThresholdII`* and `*ThresholdIF.`* A check is performed to continuously assess the RR intervals (namely the temporal interval between two consecutively QRS peaks) to overcome this issue. The average RR is computed in two ways to consider both regular and irregular heart rhythm. In the first method `*RRaverage1`* is computed as the mean of the last RR intervals. In the second method `*RRaverage2`* is computed as the mean of the last RR intervals that fell between the limits specified as:

R R l o w = 92 % % R R a v e r a g e 2 {\\displaystyle RRlow=92\\%RRaverage2}

R R h i g h = 116 % % R R a v e r a g e 2 {\\displaystyle RRhigh=116\\%RRaverage2}

If no QRS is detected in a window of 166% of the average RR (`*RRaverage1`* or `*RRaverage2`*, if the heart rhythm is regular or irregular, respectively)`*,`* the algorithm adds the maximal peak in the window as a potential QRS and classify it considering half the values of the thresholds (both `*ThresholdII and ThresholdIF`*). This check is implemented because the temporal distance between two consecutive beats cannot physiologically change more quickly than this.

>>>T wave discrimination

The algorithm takes particularly into consideration the possibility of a false detection of T waves. If a potential QRS falls up to a 160 ms window after the refractory period from the last correctly detected QRS complex, the algorithm evaluates if it could be a T wave with particular high amplitude. In this case, its slope is compared to that of the precedent QRS complex. If the slope is less than half the previous one, the current QRS is recognized as a T wave and discarded, and it also updates the `*NoiseLevel`* (both in the filtered signal and the integrated signal).

>>Application

Once the QRS complex is successfully recognized, the heart rate is computed as a function of the distance in seconds between two consecutive QRS complexes (or R peaks):

H R ( bpm ) = 60 R R ( s ) {\\displaystyle {\\mathit {HR}}\\ ({\\text{bpm}})={60 \\over {\\mathit {RR}}\\ ({\\text{s}})}}

where bpm stands for beats per minute. The HR is often used to compute the `F33f`_`[heart rate variability`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Heart_rate_variability]`_`f (HRV) a measure of the variability of the time interval between heartbeats. HRV is often used in the clinical field`:cite-ref-hrvcirc-6-0[`F5bf`_`[6`#cite-note-hrvcirc-6]`_`f] to diagnose and monitor pathological conditions and their treatment, but also in the `F33f`_`[affective computing`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Affective_computing]`_`f research to study new methods to assess the emotional state of people.`:cite-ref-7[`F5bf`_`[7`#cite-note-7]`_`f]

>>See also

• `F33f`_`[Electrophysiology`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Electrophysiology]`_`f
• `F33f`_`[QRS`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QRS]`_`f
• `F33f`_`[Heart rate`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Heart_rate]`_`f
• `F33f`_`[Heart rate variability`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Heart_rate_variability]`_`f
• `F33f`_`[Affective computing`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Affective_computing]`_`f

>>References

`:cite-note-pantompkins-1`!1.`! `F0af`_`[↑`#cite-ref-pantompkins-1-0]`_`f `:citerefpantompkins1985`aPan, Jiapu; Tompkins, Willis J. (March 1985). "A Real-Time QRS Detection Algorithm". `*IEEE Transactions on Biomedical Engineering`*. BME-32 (3): 230–236. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1109/TBME.1985.325532. `F33f`_`[PMID`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=PMID_(identifier)]`_`f 3997178.
`:cite-note-2`!2.`! `F0af`_`[↑`#cite-ref-2]`_`f `:citerefmoodymark2001`aMoody, G.B.; Mark, R.G. (2001). "The impact of the MIT-BIH Arrhythmia Database". `*IEEE Engineering in Medicine and Biology Magazine`*. `!20`! (3): 45–50. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1109/51.932724. `F33f`_`[PMID`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=PMID_(identifier)]`_`f 11446209.
`:cite-note-physionet-3`!3.`! `F0af`_`[↑`#cite-ref-physionet-3-0]`_`f `:citerefgoldbergeramaralglasshausdorff2000`aGoldberger, Ary L.; Amaral, Luis A. N.; Glass, Leon; Hausdorff, Jeffrey M.; Ivanov, Plamen Ch.; Mark, Roger G.; Mietus, Joseph E.; Moody, George B.; Peng, Chung-Kang; Stanley, H. Eugene (13 June 2000). "PhysioBank, PhysioToolkit, and PhysioNet". `*Circulation`*. `!101`! (23). `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1161/01.CIR.101.23.e215.
`:cite-note-pterrata-4`!4.`! `F0af`_`[↑`#cite-ref-pterrata-4-0]`_`f "A real time QRS detection algorithm (errata corrige)" (PDF).
`:cite-note-5`!1.`! `:citerefsedghamiz`aSedghamiz, Hooman. "Complete Pan Tompkins Implementation ECG QRS detector - File Exchange - MATLAB Central". `*ww2.mathworks.cn`*.
`:cite-note-hrvcirc-6`!6.`! `F0af`_`[↑`#cite-ref-hrvcirc-6-0]`_`f `:citereftask-force-of-the-european-society-electrophysiology1996`aTask Force of the European Society Electrophysiology (March 1996). "Heart Rate Variability". `*Circulation`*. `!93`! (5): 1043–1065. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1161/01.CIR.93.5.1043.
`:cite-note-7`!7.`! `F0af`_`[↑`#cite-ref-7]`_`f `:citerefnardellivalenzagrecolanata2015`aNardelli, Mimma; Valenza, Gaetano; Greco, Alberto; Lanata, Antonio; Scilingo, Enzo Pasquale (2015-10-01). "Recognizing Emotions Induced by Affective Sounds through Heart Rate Variability". `*IEEE Transactions on Affective Computing`*. `!6`! (4): 385–394. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1109/TAFFC.2015.2432810. `F33f`_`[hdl`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Hdl_(identifier)]`_`f:11568/765947. `F33f`_`[ISSN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISSN_(identifier)]`_`f 1949-3045.

`c`F0af`_`[↑ Back to top`#top]`_`f`a